﻿#ifndef __RENDERING_CONFIG_H__
#define __RENDERING_CONFIG_H__

#pragma once

#include "EngineCompileConfig.h"
#include "NezhaFoundation.h"

namespace Nezha
{

	// typedef RenderResource handle
	typedef int RRHandle;

	//struct _RenderingResHandle
	//{
	//	u32 mLayer;
	//	u32 Category;
	//	u32 mPoolHandle;
	//	u32 mStatu;
	//};

	//typedef _RenderingResHandle* RRHandle;

	// render layer definition, combine for mask.
	enum RenderLayer
	{
		RL_SKY = (1 << 3),
		RL_WATER = (1 << 5),
		RL_TERRAIN = (1 << 8),
		RL_VEGETATION = (1 << 10),
		RL_INSTANCING = (1 << 16),
		RL_DEFAULT = (1 << 20),
		RL_UI = (1 << 26),


		RL_ALL = 0xFFFFFFFF
	};

	enum FrameBufferType
	{
		FBO_COLOR = 0x1,
		FBO_DEPTH = 0x2,
		FBO_STENCIL = 0x4
	};

	enum SceneObjectType
	{
		SOT_UNUSABLE,
		SOT_NODE,
		SOT_CAMERA,
		SOT_LIGHT,
		SOT_AREA,
		SOT_VOLUME,
		SOT_GEOMETRY,
		SOT_STATIC_GEOMETRY,
		SOT_SKINNING_GEOMETRY,

		// TODO add new type

		// 外部类型等于： SOT_EXTERNAL_BEGIN + number (number > 0)
		SOT_EXTERNAL_BEGIN,
	};

	enum RenderObjectType
	{
		ROT_NONE = 0,
		ROT_STATIC,
		ROT_ANIMATED,
		ROT_SKINNING,
		ROT_TERRAIN,
		ROT_PARTICLE,
		ROT_VEGETATION,

		// something else?
	};

	enum RenderObjectBatch
	{
		ROB_NONE = 0,
		ROB_DYNAMIC,
		ROB_STATIC
	};

	enum BuiltInMesh
	{
		BIM_PLANE = 0,
		BIM_BOX,
		BIM_SPHERE
	};


#define NEZHA_DEFAULT_COLOR_DEPTH		32
#define NEZHA_DEFAULT_SCREEN_WIDTH		800
#define NEZHA_DEFAULT_SCREEN_HEIGHT		600

#define NEZHA_CULLING_MASK_COMMON		0x1
#define NEZHA_CULLING_MASK_ALL			0xFFFFFFFF

#define NEZHA_SORT_WITH_STATES 1

	enum RenderFlag
	{
		RENDERER_TYPE_LIGHTPREPASS= 0x1,

		RENDER_FLAG_MERGE_FORWARD_LIGHTS = 0x10,

		RENDER_FLAG_VSM = 0x100,
		RENDER_FLAG_PSM = 0x200,
		RENDER_FLAG_CSM = 0x400,
	};

	enum RenderQueueFlag
	{
		FORWARD_SHADOW_DEPTH = 1,
		FORWARD_OPAQUE_LIGHTING,
		FORWARD_OPAQUE,
		FORWARD_TRANSPARENT
	};

	enum QueueRTFlag
	{
		QUEUE_RT_UPDATE_CAM = 0x1,
		QUEUE_RT_CLEAR_VP = 0x2
	};

	class NEZHA_ENGINE_ENTRY RefCountedResManager
	{
	public:
		RefCountedResManager()
			:mGarbageDisposeInterval(5.0f)
			,mGarbageDisposeTimer(0)
		{
		}

		void update(float dt)
		{
			mGarbageDisposeTimer += dt;
			if(mGarbageDisposeTimer >= mGarbageDisposeInterval)
			{
				mGarbageDisposeTimer -= mGarbageDisposeInterval;
				_garbageDispose();
			}

			_update(dt);
		}

		float getGarbageDisposeInterval() const
		{
			return mGarbageDisposeInterval;
		}

		void setGarbageDisposeInterval(float interval)
		{
			mGarbageDisposeInterval = interval;
		}

	protected:
		virtual void _update(float dt) {}

		virtual void _garbageDispose() = 0;

	private:
		float mGarbageDisposeInterval;
		float mGarbageDisposeTimer;
	};

}

#endif //end __RENDERING_CONFIG_H__